<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="javatime" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<% String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <base href=<%=basePath%>
          <%@include file="../common_css.jsp" %>
                  </head>
<body class="childrenBody">
<form class="layui-form" style="width:80%;">
    <input type="hidden" name="id" value="${cancelApply.id}">
    <input type="hidden" name="orderId" value="${cancelApply.orderId}">
    <input type="hidden" name="cusId" value="${cancelApply.cusId}">
    <div class="layui-form-item layui-row">
        <div class="layui-col-xs6">
            <label class="layui-form-label">订单编号</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input"
                       lay-verify="required" name="order_id" id="order_id" value="${cancelApply.cusOrder.orderId}"
                       readonly
                >
            </div>
        </div>
        <div class="layui-col-xs6">
            <label class="layui-form-label">客户姓名</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input"
                       lay-verify="required" name="customerName" id="customerName" value="${cancelApply.customer.name}"
                       readonly
                >
            </div>
        </div>
    </div>


    <div class="layui-form-item layui-row">
        <div class="layui-col-xs6">
            <label class="layui-form-label">车型</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input"
                       name="car" id="car" value="${cancelApply.car.series} ${cancelApply.car.model}"
                       readonly
                >
            </div>
        </div>
        <div class="layui-col-xs6">
            <label class="layui-form-label">员工姓名</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input"
                       name="user" id="user" value="${cancelApply.customer.user.name}"
                       readonly
                >
            </div>
        </div>
    </div>
    <div class="layui-form-item layui-row">
        <div class="layui-col-xs6">
            <label class="layui-form-label">退款金额</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" id="price" name="price"
                       value="5000"
                       readonly
                >
            </div>
        </div>
    </div>
    <div class="layui-form-item layui-row">
        <label class="layui-form-label">退订原因</label>
        <div class="layui-input-block">
            <textarea name="cause" id="cause" class="layui-textarea" lay-verify="required"
                      readonly>${cancelApply.cause}</textarea>
        </div>
    </div>

    <div class="layui-form-item layui-row">
        <div class="layui-col-xs6">
            <label class="layui-form-label">是否同意</label>
            <input type="checkbox" lay-filter="filter" name="cancelState" title="是" value="1" <c:if test="${cancelApply.cancelState == 1}">checked</c:if>
                   <c:if test="${cancelApply.handleState == 2}">disabled</c:if>>
            <input type="hidden" name="cancelStateHidden" value="2">
        </div>
    </div>

    <div class="layui-form-item layui-row">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <textarea name="remarks" id="remarks" class="layui-textarea" lay-verify="required" <c:if test="${cancelApply.handleState==2}">readonly</c:if>><c:if test="${cancelApply.handleState==2}">${cancelApply.remarks}</c:if></textarea>
        </div>
    </div>

    <br/>
    <c:if test="${cancelApply.handleState==1}">
        <div class="layui-form-item layui-row layui-col-xs12">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-lg" lay-submit=""
                        lay-filter="saveCancelApply">确认
                </button>
                <button class="layui-btn layui-btn-lg layui-btn-normal">取消</button>
            </div>
        </div>
    </c:if>

</form>
<script type="text/javascript">
    layui.use(['form', 'layer','jquery'], function () {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery;
        form.on('checkbox(filter)', function (data) {
            if (data.elem.checked) {
                $("[name=cancelStateHidden]").val(1)
            } else {
                $("[name=cancelStateHidden]").val(2)
            }
        });

        form.on('submit(saveCancelApply)', function () {
            var index= top.layer.msg("数据提交中,请稍后...",{icon:16,time:false,shade:0.8});
            $.ajax({
                url: "cancelApply/processCancelApply",
                type: "post",
                data: {
                    cancelState: $("[name=cancelStateHidden]").val(),
                    remarks: $("[name=remarks]").val(),
                    id: $("[name=id]").val(),
                    orderId: $("[name=orderId]").val(),
                    cusId: $("[name=cusId]").val(),
                    price:$("[name=price]").val()
                },
                success: function (res) {
                    if (res == 'success') {
                        top.layer.msg("操作成功");
                        top.layer.close(index);
                        layer.closeAll("iframe");
                        // 刷新父页面
                        parent.location.reload();
                    }
                }
            })
            return false;
        });
    });
</script>
</body>
</html>